<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="path" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>${model.comment}</title>
<%@ include file="/WEB-INF/views/mis/common_inc.jsp"%>
</head>
<style>
</style>
<body style="padding:0 10px;height:100%;overflow:hidden">
	<div class="main-div">
		<!-- 过滤条件 -->
		<div class="search-div">
			<form id="searchForm" method="get" >
				<table>
					<tr>
						<td>
							<ul>
								<li>
									<label>name</label>
									<div><input type="text" id="name" name="name" placeholder="name"></div>
								</li>
								 
								<li>
									<label>创建时间</label>
									<div>
										<input type="text" class="lay-date" placeholder="开始日期" onclick="layui.laydate({elem: this})" id="search_beginDate" name="search_beginDate">
										~
										<input type="text" class="lay-date" placeholder="结束日期" onclick="layui.laydate({elem: this})" id="search_endDate" name="search_endDate">
									</div>
								</li>
							</ul>
						</td>
						<td width="220px" align="right" valign="bottom">
							<button type="button" class='layui-btn layui-btn-small' onClick="doSearch_dg()"><i class='layui-icon'>&#xe615;</i> 查询</button>
							<button type="button" class='layui-btn layui-btn-small' onClick="doAdd_dg()"><i class='layui-icon'>&#xe654;</i> 新增</button>
						</td>
					</tr>
				</table>
				
				
			</form>
		</div>
		<!-- 列表 -->
		<div class="grid-div">
			<table id="dg_table" ></table>
		</div>
	</div>
</body>
<script type="text/javascript">
var	dg_list=null;
$(function(){
	dg_list = $('#dg_table').datagrid(
			{
 				url : '${path}/${model.modelL}/list',
				method : 'get',
				pagination : true,
				pageSize:20,
				pageList:[10,20,30,50,100,200,300],
				fitColumns : true,
				border:false,//grid边框
				height:$("body").height()-$(".search-div").outerHeight()-10,//设置grid高度自适应页面高度
	            nowap: false, //列内容多时自动折至第二行
				sortName : 'CREATE_TIME', 
				sortOrder : 'desc',
				showFooter : false,
				remoteSort : true,
				loadFilter:function(d){ return d},//去掉json根目录匹配datagrid所需格式
				emptyMsg:"未查到数据",
				columns : [ [
				{field : 'code',hidden : true},
				//注意width属性的值不要加引号，如果加引号每次点击查询功能的时候单元格会自动拉宽
#foreach( $field in $fieldList )
#if($field.listShow == true&&${field.field}!="code"&&${field.inputType}!="hidden"&&${field.field}!="delFlag")
            {
                width : 80,
                title : '${field.comment}',
                field : '${field.columnName}',
            },
#end
#end
						{field:'action',title : '操作',align : 'center',width : 100,
							formatter : function(value, row,index) {
								var str = "";
								 str += "<a class='layui-btn layui-btn-mini layui-btn-normal' onclick='edit${model.model}(\""+row.code+"\")'>编辑</a>";
									str += "<a  class='layui-btn layui-btn-mini layui-btn-danger' onclick='delete${model.model}(\""+row.code+"\")'>删除</a>";
									str += "<a class='layui-btn layui-btn-mini layui-btn-normal' onclick='details${model.model}(\""+row.code+"\")'>详情</a>";
							    return str;
							}
						} 	
					] ]
			});
	
});
//查询列表
$("#searchForm").keydown(function(e){
   if(e.keyCode==13){
	   doSearch_dg();
   }
});
function doSearch_dg(){
	dg_list.datagrid({url : '${path}/${model.modelL}/list',queryParams : form2Json("searchForm")});
}
function form2Json(id) {
	var arr = $("#" + id).serializeArray()
	var jsonStr = "";
	jsonStr += '{';
	for (var i = 0; i < arr.length; i++) {
		jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
	}
	jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
	jsonStr += '}'

	var json = JSON.parse(jsonStr)
	return json
}
//新增
function doAdd_dg(){
	layer.open({
	  type: 2,
	  title: '新增',
	  shadeClose: false,
	  shade: 0.1,
// 	  skin:'layui-layer-molv',
	 area: ['300px', '300px'],
	  content: '${path}/${model.modelL}/add'
	}); 
}
 
//删除
function delete${model.model}(code){
	
	layer.confirm('是否删除？', {
		  btn: ['删除','取消'] //按钮
		}, function(){
			 $.post('${path}/${model.modelL}/delete?code='+code,function(data){
				data=$.parseJSON(data); 
				layer.close('dialog');
				layer.msg(data.message);
				doSearch_dg();
			});
		});
	 
}
//编辑
function edit${model.model}(code){
	layer.open({
	  type: 2,
	  title: '编辑',
	  shadeClose: false,
	  shade: 0.1,
// 	  skin:'layui-layer-molv',
	area: ['300px', '300px'],
	  content: '${path}/${model.modelL}/edit?code='+code
	}); 
}
//查看详情
function details${model.model}(code){
	layer.open({
	  type: 2,
	  title: '详情',
	  shadeClose: false,
	  shade: 0.1,
// 	  skin:'layui-layer-molv',
	  area: ['300px', '300px'],
	  content: '${path}/${model.modelL}/detail?code='+code
	}); 
}
</script>
</html>